'  ==========================================================================
'  |                                                                        |
'  | SQLitening Procs Suffix B                                              |
'  |                                                                        |
'  ==========================================================================
'
'  ==========>>> General to All Procs
'  Procs will allow you to write your own code which will run at the server
'  accessing SQLite in local mode.  These Procs can talk directly to SQLite 
'  or can go thru SQLitening.  Not using SQLitening could result in a slightly
'  more efficient Proc but is harder to develop.  Procs will also work fine 
'  at the client in local mode. This concept is similar to database procedures 
'  in Oracle and MySQL except here you get to code in Basic (or any language 
'  than can produce a standard DLL) rather that their proprietary language. 
'  Using Procs can greatly improve response time by reducing messages to/from 
'  the server.  You must developing a Proc very carefully because it runs as 
'  part of the service on the server.  If your Proc crashes your service will 
'  also crash.  Your Proc must do proper clean-up.  You must close all open 
'  connections, databases, and  sets before ending/unloading.
'  CAUTION1:  This DLL is running as part of the service on the server so all 
'             sets must be closed/finalized ASAP so locks are released. (don't 
'             return to the caller with open/un-finalized sets)
'  CAUTION2:  This DLL must be thread safe so careful with globals or use
'             Threaded global variables.
'   All Procs that are to be called with slRunProc must be named SQLiteningProc?.Dll 
'   where ? must be a single alpha suffix character of A thru Z.  Each Proc can have 
'   as many entries as required and may be named whatever you would like.  The suffix 
'   and entry name are used in slRunProc.  Each entry must receive the following parms 
'   and returns a Long:  
'              byval rhDab as Dword, _
'              byval rlTcpFileNumber as Long, _
'              blParm1 as Long, _
'              blParm2 as Long, _
'              bsParm3 as String, _
'              bsParm4 as String)Export as Long
'   If the Proc is called by using the load_extension SQLite function then the only 
'   parm is Dab and returs a Long:
'              byval rhDab as Dword
'   If a database is open when the Proc is called then Dab will contain
'   the handle and it can be used to do SQLite calls directly or can be passed 
'   to slOpen so that the previously openned database can inherited by SQLitening.Dll.
'   If Dab is zero then the database must be opened here and then closed before 
'   returning. If running remote then TcpFileNumber will contain the unique number 
'   assigned by the server to this connection or zero if running local.   Note 
'   that the two longs and two strings parms are both received and passed (in and 
'   out).  These are the four parms you will use to communicate with the Proc using
'   slRunProc.  The return value from this function must be zero if all OK or non
'   zero if an error occurs.
' 
'  ==========>>> About this sample Proc
'   This Proc contains the follow two sample entries:
'   Entry 1 ===>>>  
'        Will inherit the database handle from the caller. Returns selected data from
'        Parts table and from an attached database named T.  This entry calls
'        SQLitening for all processing.
'   Entry 2 ===>>>
'       This example opens it's database rather than inheriting and also attaches
'       a database and names it T.  Returns selected data from Parts table and from 
'       the attached database named T.  This entry calls SQLitening for all processing.
'       Note that the slClose is REQUIRED!!!
'  ==========================================================================
'  PUBLIC DOMAIN SOFTWARE
'  The author or authors of this code dedicate any and all
'  copyright interest in this code to the public domain.
'  Anyone is free to copy, modify, publish, use, compile,
'  sell, or distribute the original code, either in source
'  code form or as a compiled binary, for any purpose,
'  commercial or non-commercial, and by any means.
'  Fred Meier - July 2010
'  ==========================================================================

#Compile Dll "..\Bin\SQLiteningProcsB.Dll"
#Dim All
#Include "AxRed.inc"
#Include "SQLitening.inc"

'============================<[ Entry 1 ]>=============================
Function Entry1 alias "Entry1" (byval rhDab as Dword, _
                                byval rlTcpFileNumber as Long, _
                                blParm1 as Long, _
                                blParm2 as Long, _
                                bsParm3 as String, _
                                bsParm4 as String)Export as Long

   if isfalse rhDab then exit function
   slOpen format$(rhDab)
   bsParm3 = slSelStr("Select RowID, Product from Parts")
   bsParm4 = slSelStr("Select * from T.T1")

End Function

'============================<[ Entry 2 ]>=============================
Function Entry2 alias "Entry2" (byval rhDab as Dword, _
                                byval rlTcpFileNumber as Long, _
                                blParm1 as Long, _
                                blParm2 as Long, _
                                bsParm3 as String, _
                                bsParm4 as String)Export as Long

   slOpen "sample.db3"
   slAttach "Test.Sld", "T"
   bsParm3 = slSelStr("Select RowID, Product from Parts")
   bsParm4 = slSelStr("Select * from T.T1")
   slClose

End Function

